package be.kuleuven.cs.mume.actions;

import org.mt4j.components.visibleComponents.shapes.AbstractShape;
import org.mt4j.components.visibleComponents.shapes.MTLine;
import org.mt4j.components.visibleComponents.shapes.MTRectangle;
import org.mt4j.sceneManagement.IPreDrawAction;
import org.mt4j.util.math.Vertex;

import be.kuleuven.cs.mume.objects.HelloWorldObject;

public class UpdateConnLine implements IPreDrawAction {
	
	private AbstractShape rect;
	private AbstractShape rect2;
	private MTLine connectLine;
	
	public UpdateConnLine(AbstractShape rect, AbstractShape rect2, MTLine connectLine) {
		this.rect = rect;
		this.rect2 = rect2;
		this.connectLine = connectLine;
	}

	public boolean isLoop() {
		// TODO Auto-generated method stub
		return true;
	}

	public void processAction() {
		updateLine(connectLine,rect.getCenterPointGlobal().x,rect.getCenterPointGlobal().y,rect2.getCenterPointGlobal().x,rect2.getCenterPointGlobal().y);
	}
	
	private void updateLine(MTLine line, float startX, float startY, float endX, float endY) {
		Vertex[] lineVertices = line.getVerticesGlobal();

		lineVertices[0].x = startX;
		lineVertices[0].y = startY;
		lineVertices[1].x = endX;
		lineVertices[1].y = endY;

		line.setVertices(lineVertices);
	}

}
